package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.exceptions.NotEnoughFundsException;


public class Client {
	
	private Account account; // Every client can have (and should have one Account)
	private String firstName;
	private String lastName;
	private Gender gender; // ENUM
	
	/**
	 * Constructor with empty parameters
	 */
	public Client(){
		this.account = (Account) new SavingAccount(0);
	}
	
	/**
	 * Let's create object only with startBalance
	 * @param startBalance
	 */
	public Client(double startBalance){
		this.account = (Account) new SavingAccount(startBalance);
	}
	
	/**
	 * Client with 
	 * @param fn First Name
	 * @param ln Last name
	 * @param gen Gender ENUM
	 * @param startBalance How much money )
	 */
	public Client(String fn, String ln, Gender gen, double startBalance){
		this.account = (Account) new SavingAccount(startBalance);
		this.gender = gen;
		this.firstName = fn;
		this.lastName = ln;
	}
	
	/**
	 * Client with overdraft, only these clients have CheckingAccount
	 * @param fn First Name
	 * @param ln Last Name
	 * @param gen Gender ENUM
	 * @param startBalance Money, money, money
	 * @param overdraft Max overdraft of this client
	 */
	public Client(String fn, String ln, Gender gen, double startBalance, double overdraft){
		this.account = (Account) new CheckingAccount(startBalance, overdraft); // Only here we will create instance of CheckingAccount. And (cast) it to Account.
		this.gender = gen;
		this.firstName = fn;
		this.lastName = ln;
	}
	
	public double getBalance(){
		return this.account.getBalance(); // Chain of responsibility?
	}
	
	public String getClientSalutation(){
		String prefix = this.gender.getPrefix();
		return prefix + " "+this.firstName;
	}
	
	public double getMaximumAmountToWithdraw(){
		return this.account.maximumAmountToWithdraw(); //Chain of responsibility?
	}
	
	public void withdraw(double x) throws NotEnoughFundsException{
		if (x >= 0){
			this.account.withdraw(x); //Chain of responsibility?
		}
		else{
			throw new NotEnoughFundsException();
		}
	}
	
	public void deposit(double x){
		this.account.deposit(x); //Chain of responsibility?
	}
	
	public String toString(){
		return "This is client " + this.getClientSalutation() + " " + this.firstName + " " +this.lastName;
	}
	
	public boolean equals(Client cl){
		boolean result = cl.firstName == this.firstName && cl.lastName == this.lastName;
		return result;
	}
}
